import request from "@/utils/request"
import { setRandomPage } from "@/utils/storage"

/**
 * 分页获取商品
 */
export function getPage(params) {
  return request.get('/products/get-page', { params })
}

export function getCount(params?, limit?) {
  return request.get('/products/get-page', { params: { page: 1, limit: 1, ...params } }).then(res => {
    const { totalCount } = res.data
    const page = Math.ceil(totalCount/(limit || 10))
    const arr:any = []
    for (let i=1; i<=page; i++) {
      arr.push(i)
    }
    setRandomPage(arr)
    return res
  })
}

/**
 * 获取商品详情
 */
export function infoById(id, params?) {
  return request.get(`/products/get-by-id/${id}`, params)
}

/**
 * 获取商品sku
 */
export function skuById(id) {
  return request.get(`/products/get-sku-by-id/${id}`)
}
